package com.website.view.menu
{
	import com.bakh.picWall.Bakh3DWall;
	import com.greensock.TweenMax;
	import com.website.control.PathManager;
	import com.website.data.ProjectsXml;
	import com.website.util.Constant;
	import com.website.util.DisplayUtil;
	import com.website.view.PicListPanel;
	import com.website.view.UI_HorizontalRule;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class NavComponent extends Sprite
	{
		public var hRule1:UI_HorizontalRule;
		public var hRule2:UI_HorizontalRule;
//		public var hRule3:UI_HorizontalRule;
		private var _navMenuArray:Array;
		public var practiceMenu:NavMenu;
		public var contactMenu:NavMenu;
		public var newsMenu:NavMenu;
		public var projectsMenu:NavMenu;
		private var _picListPanel:PicListPanel = new PicListPanel();
		private var _bakh3DWall:Bakh3DWall;
		public function NavComponent()
		{
			super();
			_navMenuArray = new Array();
			createRule();
		}

		private function createRule():void
		{
			hRule1 = new UI_HorizontalRule();
			hRule1.alpha = 1;
			addChild(hRule1);
			hRule2 = new UI_HorizontalRule();
			hRule2.alpha = 1;
			addChild(hRule2);
			hRule1.x = Math.round(4 * (Constant.unitW + Constant.gutterW));
//			hRule1.y = Math.round(_bar.height + Constant.unitH + 4 / 9 * Constant.gutterH);
			hRule1.width = Math.round(8 * Constant.unitW + 7 * Constant.gutterW);
			hRule1.height = 1;
			hRule1.y = 160;//110;
//			hRule2.y = Math.round(_bar.height + 2 * Constant.unitH + Constant.gutterH);
//			hRule2.y = 0;//210;
			hRule2.width = Math.round(Constant.gridCurrW);
			hRule2.height = 1;
//			hRule3 = new UI_HorizontalRule();
//			hRule3.alpha = 1;
////			hRule3.y = Math.round(Constant.gridCurrH);
//			hRule3.width = Math.round(Constant.gridCurrW);
//			hRule3.height = 1;
			addChild(_picListPanel);
			_picListPanel.y = 8;
			_picListPanel.x = 35;
//			hRule1.visible = false;
//			hRule2.visible = false;
//			hRule3.visible = false;
		}
		
		private function buildCols(id:int) : void
		{
			if (id == 0)
			{
				projectsMenu = new NavMenu( "tier0", "projectsMenu", ProjectsXml.projectsxml.tier0);
				projectsMenu.name = "projectsMenu";
				_navMenuArray[0] = projectsMenu;
				_navMenuArray[0].visible = false;
				_navMenuArray[0].alpha = 0;
				addChild(_navMenuArray[0]);
			}
			if (id == 1)
			{
				practiceMenu = new NavMenu( "tier0", "practiceMenu", ProjectsXml.practice.tier0);
				practiceMenu.name = "practiceMenu";
				_navMenuArray[1] = practiceMenu;
				_navMenuArray[1].visible = false;
				_navMenuArray[1].alpha = 0;
				addChild(_navMenuArray[1]);
			}
			if (id == 2)
			{
				contactMenu = new NavMenu( "tier0", "contactMenu", ProjectsXml.contact.tier0);
				contactMenu.name = "contactMenu";
				_navMenuArray[2] = contactMenu;
				_navMenuArray[2].visible = false;
				_navMenuArray[2].alpha = 0;
				addChild(_navMenuArray[2]);
			}
			if (id == 3)
			{
				newsMenu = new NavMenu( "tier0", "newsMenu", ProjectsXml.news.item);
				newsMenu.name = "newsMenu";
				_navMenuArray[3] = newsMenu;
				_navMenuArray[3].visible = false;
				_navMenuArray[3].alpha = 0;
				addChild(_navMenuArray[3]);
			}
			doReSize();
		}
		
		public function switchCols(switchId:Number) : void
		{
//			fadeBtns();
			if (switchId == 0)
			{
				PathManager.pathNames[0] = "projects";
			}
			else if (switchId == 1)
			{
				PathManager.pathNames[0] = "practice";
			}
			else if (switchId == 2)
			{
				PathManager.pathNames[0] = "contact";
			}
			else if (switchId == 3)
			{
				PathManager.pathNames[0] = "news";
			}
			else if (switchId == 4)
			{
				PathManager.pathNames[0] = "bookmarks";
			}
			else if (switchId == 5)
			{
				PathManager.pathNames[0] = "search";
			}
			DisplayUtil.removeFromParent(_picListPanel);
//			_bakh3DWall = new Bakh3DWall();
//			addChild(_bakh3DWall);
			if (_navMenuArray[switchId] == undefined)
			{
				buildCols(switchId);
			}
//			hRule3.visible =
			hRule1.visible = hRule2.visible =  true; 
			var index:int = 0;
			while (index < _navMenuArray.length)
			{
				
				if (index != switchId)
				{
					if (_navMenuArray[index] != undefined)
					{
						_navMenuArray[index].fadeOutShell();
//						TweenMax.to(navArray[index], Constant.fadeSpeed, {tint:12500670, overwrite:true});
					}
				}
				else if (_navMenuArray[index] != undefined)
				{
					_navMenuArray[index].fadeInShell();
				}
				index++;
			}
			return;
		}
		
		private function doReSize():void
		{
			var posArr:Array = [
				4 * (Constant.unitW + Constant.gutterW), 
				5 * (Constant.unitW + Constant.gutterW), 
				6 * (Constant.unitW + Constant.gutterW), 
				7 * (Constant.unitW + Constant.gutterW), 
				8 * (Constant.unitW + Constant.gutterW), 
				10 * (Constant.unitW + Constant.gutterW)];
			
			var i:int = 0;
			while (i < 5)
			{
				if (_navMenuArray[i] != undefined)
				{
					_navMenuArray[i].x = Math.round(posArr[i]);
					_navMenuArray[i].y = 160;//28 * Constant.unitW / 75;
				}
				i++;
			}
		}
		
		public function hRule1On() : void
		{
			TweenMax.to(hRule1, Constant.fadeSpeed, {alpha:1, overwrite:true});
			return;
		}
	}
}